package cybertechcebu
{	
	import flashx.textLayout.elements.ParagraphElement;
	import flashx.textLayout.elements.SpanElement;
	
	import spark.components.TextArea;

	public class Console
	{
		private static const RED:uint = 0xFF0000;
		private static const BLUE:uint = 0x0000FF;
		private static const GREEN:uint = 0x00FF00;
		private static const LIGHT_GRAY:uint = 0xD3D3D3;
		private static const BLACK:uint = 0x000000;
		private static var _textArea:TextArea;
		
		public function Console()
		{
			throw Error("Private constructor unta");
		}
		
		public static function initialize(textArea:TextArea):void{
			_textArea = textArea;
		}
		
		private static function scrollDown():void
		{
			_textArea.validateNow();
			_textArea.scroller.verticalScrollBar.value = _textArea.scroller.verticalScrollBar.maximum;
		}
		
		public static function log(type:String, mesg:String, color:uint):void
		{
			var paragraph:ParagraphElement = new ParagraphElement();
			var span:SpanElement = new SpanElement();
			span.text = "[" + type + "] " + mesg;
			span.color = color;
			paragraph.addChild(span);
			_textArea.textFlow.addChild(paragraph);
			scrollDown();
		}
		
		public static function error(string:String):void
		{
			log("error", string, RED);
		}
		
		public static function progress(string:String):void
		{
			log("progress", string, LIGHT_GRAY);
		}
		
		public static function command(string:String):void
		{
			log("command", string, BLUE);
		}
		
		public static function response(string:String):void
		{
			log("response", string, GREEN);
		}

	}
}